<template>
  <div>
    <!-- 面包导航 -->
    <el-breadcrumb separator="/" style="padding-left:10px;padding-bottom:10px;font-size:12px;">
      <el-breadcrumb-item :to="{ path: '/main' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>物资管理</el-breadcrumb-item>
      <el-breadcrumb-item>物资资料</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 主体内容 -->
    <el-card class="box-card">

      <!-- 友情提示 -->
      <el-container style="margin-bottom:20px;">
        <el-alert
          show-icon
          title="友情提示:  商品的分类只支持三级分类"
          type="warning">
        </el-alert>
      </el-container>

      <!-- 搜索 -->
      <el-row :gutter="6" style="margin-bottom:20px;">

        <!-- 下拉框联动 -->
        <el-col :span="5">
          <el-cascader
            :options="options"
            :props="{ checkStrictly: true }"
            clearable></el-cascader>
        </el-col>

        <!-- 文本框搜索 -->
        <el-col :span="6">
          <el-input
            clearable
            v-model="queryMap.name"
            placeholder="请输入物资名称查询"
            @clear="search"
            class="input-with-select"
          ></el-input>
        </el-col>

        <!-- 普通下拉框 -->
        <el-col :span="5">
          <template>
            <el-select v-model="queryMap.status" @click="search" placeholder="请选择状态">
              <el-option label="正常" :value="0"></el-option>
              <el-option label="回收站" :value="1"></el-option>
              <el-option label="待审核" :value="2"></el-option>
            </el-select>
          </template>
        </el-col>

        <!-- 按钮 -->
        <el-col :span="8">
          <el-button type="primary" icon="el-icon-search" @click="search">查找</el-button>
          <el-button icon="el-icon-refresh-right" type="warning" @click="resetForm">重置</el-button>
          <el-button type="success" icon="el-icon-circle-plus-outline" @click="edit">添加</el-button>
          <el-button icon="el-icon-refresh" @click="getproductList">刷新</el-button>
        </el-col>
      </el-row>

      <!-- 表格区域 -->
      <template>
        <el-table
          :data="scope"
          height="450"
          border
          style="width: 100%">

          <el-table-column
            prop="id"
            label="ID"
            width="60px">
          </el-table-column>

          <el-table-column prop="imageUrl" label="图片" align="center" width="150px" padding="0px">
            <template slot-scope="scope">
              <el-popover placement="right"  trigger="hover">
                <img :src="scope.row.imageUrl"  style="height: 200px;width: 200px"/>
                <img  slot="reference" :src="scope.row.imageUrl" :alt="scope.row.imgUrl" style="height: 38px;width: 38px;cursor: pointer">
              </el-popover>
            </template>
          </el-table-column>

          <el-table-column
            prop="name"
            label="物资名称"
          >
          </el-table-column>

          <el-table-column
            prop="pNum"
            label="物资编号"
          >
          </el-table-column>


          <el-table-column
            prop="tag"
            label="物资规格"
            filter-placement="bottom-end">
            <template slot-scope="scope">
              <el-tag
                type="success"
                disable-transitions
              >{{scope.row.model}}</el-tag>
            </template>
          </el-table-column>

          <el-table-column
            prop="unit"
            label="单位"
          >
          </el-table-column>

          <el-table-column
            prop="remark"
            label="备注"
          >
          </el-table-column>

          <el-table-column
            prop="tag"
            label="状态"
            filter-placement="bottom-end">
            <template slot-scope="scope">
              <el-tag size="mini"  type="danger" effect="plain" v-if="scope.row.status==1">回收</el-tag>
              <el-tag size="mini"  effect="plain" type="primary" v-if="scope.row.status==0">正常</el-tag>
              <el-tag size="mini"  effect="plain" type="warning" v-if="scope.row.status==2">审核中</el-tag>
            </template>
          </el-table-column>

          <el-table-column
            prop="createTime"
            label="创建时间"
            width="160px">
          </el-table-column>

          <el-table-column
            label="操作">

            <!--给管理员提供的恢复和删除-->
<!--            <span v-if="scope.row.status==1">-->
              <!-- 恢复 -->
<!--              <el-popconfirm-->
<!--                @onConfirm="back(scope.row.id)"-->
<!--                style="margin-left:10px;"-->
<!--                confirmButtonText='好的'-->
<!--                cancelButtonText='不用了'-->
<!--                icon="el-icon-info"-->
<!--                iconColor="green"-->
<!--                title="这是一段内容确定恢复吗？"-->
<!--              >-->
<!--                <el-button type="text" size="mini" slot="reference" icon="el-icon-back">恢复</el-button>-->
<!--              </el-popconfirm>-->
<!--              <el-button style="margin-left:10px;" type="text" size="mini"  icon="el-icon-delete" @click="del(scope.row.id)">删除</el-button>-->
<!--            </span>-->

            <!--              给操作员提供的编辑和回收-->
<!--            <span v-if="scope.row.status==0" >-->
              <el-button type="text" size="mini" icon="el-icon-edit" @click="edit">编辑</el-button>
              <!-- 逻辑删除 -->
              <el-popconfirm
                @onConfirm="remove(scope.row.id)"
                style="margin-left:10px;"
                confirmButtonText='好的'
                cancelButtonText='不用了'
                icon="el-icon-info"
                iconColor="red"
                title="这是一段内容确定移入回收站吗？"
              >
                <el-button type="text" slot="reference" size="mini" icon="el-icon-s-operation">回收站</el-button>
              </el-popconfirm>
<!--            </span>-->

<!--            给管理员提供的审核和不通过-->
<!--            <span  v-if="scope.row.status==2">-->
<!--            <el-popconfirm-->
<!--              @onConfirm="publish(scope.row.id)"-->
<!--              style="margin-left:10px;"-->
<!--              confirmButtonText='是的'-->
<!--              cancelButtonText='不用了'-->
<!--              icon="el-icon-info"-->
<!--              iconColor="blue"-->
<!--              title="确定审核通过吗？"-->
<!--            >-->
<!--              <el-button type="text" slot="reference" size="mini" icon="el-icon-s-operation">通过</el-button>-->
<!--            </el-popconfirm>-->
<!--              <el-button style="margin-left:10px;" type="text" size="mini" icon="el-icon-delete"-->
<!--                         @click="del(scope.row.id)">删除-->
<!--              </el-button>-->
<!--            </span>-->
          </el-table-column>
        </el-table>
      </template>

      <!-- 分页 -->
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page= queryMap.pageNum
          :page-sizes="[5, 10, 15, 20]"
          :page-size= queryMap.pageSize
          layout="total, sizes, prev, pager, next, jumper"
          :total= queryMap.total>
        </el-pagination>
      </div>


      <!-- 弹窗 -->
      <el-dialog title="编辑物资" :visible.sync="dialogFormVisible">
        <span>
          <el-form
            :model="productForm"
            :rules="formRules"
            ref="addRuleFormRef"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="物资名称" prop="name">
              <el-input v-model="productForm.name"></el-input>
            </el-form-item>

            <el-form-item label="物资图片" prop="name">
              <!-- 图片上传部分 -->
              <el-upload
                action="https://jsonplaceholder.typicode.com/posts/"
                list-type="picture-card"
                :on-preview="handlePictureCardPreview"
                :on-remove="handleRemove">
                <i class="el-icon-plus"></i>
              </el-upload>
            </el-form-item>

            <el-row>
              <el-col :span="12">
                <div class="grid-content bg-purple-light">
                  <el-form-item label="物资规格" prop="model">
                    <el-input v-model="productForm.model"></el-input>
                  </el-form-item>
                </div>
              </el-col>

              <el-col :span="12">
                <div class="grid-content bg-purple">
                  <el-form-item label="分类" prop="categoryKeys">
                    <el-cascader
                      :options="options"
                      clearable
                      filterable
                      v-model="productForm.categoryKeys"
                    ></el-cascader>
                  </el-form-item>
                </div>
              </el-col>
            </el-row>

            <el-row>
              <el-col :span="12">
                <div class="grid-content bg-purple">
                  <el-form-item label="单位" prop="unit">
                    <el-input v-model="productForm.unit"></el-input>
                  </el-form-item>
                </div>
              </el-col>

              <el-col :span="12">
                <div class="grid-content bg-purple-light">
                  <el-form-item label="排序" prop="sort">
                    <el-input-number v-model="productForm.sort" :min="1" :max="10" label="排序"></el-input-number>
                  </el-form-item>
                </div>
              </el-col>
            </el-row>

            <el-form-item label="备注信息" prop="remark">
              <el-input type="textarea" v-model="productForm.remark"></el-input>
            </el-form-item>
          </el-form>
        </span>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
        </div>
      </el-dialog>

    </el-card>
  </div>
</template>

<script>
    export default {
        name: "Products",
        data() {
            return {
                // 查询对象
                queryMap: {
                    pageNum: 1,
                    pageSize: 5,
                    total: 100,
                    name: "",
                    categoryId: "",
                    supplier: "",
                    status: 0

                },
                // 下拉框联动
                options: [{
                    value: 'zhinan',
                    label: '指南',
                    children: [{
                        value: 'shejiyuanze',
                        label: '设计原则',
                        children: [{
                            value: 'yizhi',
                            label: '一致'
                        }, {
                            value: 'fankui',
                            label: '反馈'
                        }, {
                            value: 'xiaolv',
                            label: '效率'
                        }, {
                            value: 'kekong',
                            label: '可控'
                        }]
                    }, {
                        value: 'daohang',
                        label: '导航',
                        children: [{
                            value: 'cexiangdaohang',
                            label: '侧向导航'
                        }, {
                            value: 'dingbudaohang',
                            label: '顶部导航'
                        }]
                    }]
                }],
                // 表格内容
                scope: [{
                    id: 1,
                    name: 'N95口罩',
                    pNum: '3DFC8EA0-6',
                    model: '舒适版',
                    status: 0,
                    imageUrl: 'https://i.loli.net/2020/12/03/bWetg1JvPM5hSEp.jpg',
                    unit: '包',
                    remark: '救命的口罩',
                    createTime: '2020-03-18 00:00:00'
                }],
                /* 会话弹窗 */
                dialogFormVisible: false,
                productForm: {
                    name: '',
                    model: '',
                    unit: '',
                    sort: '',
                    remark: '',
                    categoryKeys: ''
                },
                /* 表单验证 */
                formRules: {
                    name: [
                        { required: true, message: "请输入物资名称", trigger: "blur" },
                        { min: 2, max: 10, message: "长度在 2 到 10 个字符", trigger: "blur" }
                    ],
                    unit: [
                        { required: true, message: "请输入物资单位", trigger: "blur" },
                        { min: 1, max: 10, message: "长度在 1 到 10 个字符", trigger: "blur" }
                    ],
                    model: [
                        { required: true, message: "请输入物资规格", trigger: "blur" },
                        { min: 2, max: 10, message: "长度在 2 到 10 个字符", trigger: "blur" }
                    ],
                    remark: [
                        { required: true, message: "请输入物资说明备注", trigger: "blur" },
                        { min: 2, max: 10, message: "长度在 2 到 10 个字符", trigger: "blur" }
                    ],
                    categorys: [
                        { required: true, message: "请输入物资分类", trigger: "blur" }
                    ],
                    sort: [{ required: true, message: "请输入地址信息", trigger: "blur" }],
                    categoryKeys: [
                        { required: true, message: "请选择物资分类", trigger: "blur" }
                    ]
                }
            }
        },
        methods: {
            /* 搜索物资方法 */
            search() {

            },
            /* 重置查询表单 */
            resetForm() {
                this.queryMap = {
                    pageNum: 1,
                    pageSize: 5,
                    name: "",
                    categoryId: "",
                    supplier: "",
                    status: 0
                };
            },
            /* 加载物资列表 */
            getproductList() {

            },
            /* 逻辑删除 */
            remove(row) {

            },
            /* 删除 */
            del(id) {

            },
            /* 编辑 */
            edit(){
                this.dialogFormVisible = true;
            },
            /* 分页 */
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
            },
            /* 图片处理 */
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            }
        }
    }
</script>

<style scoped>

</style>
